import 'package:flutter/material.dart';

class ListViewCase extends StatefulWidget {
  // 2.根据构造函数生成对应的数据
   final List<GoodsItem> list = [
    GoodsItem(
      picture: "https://img2.baidu.com/it/u=2051424033,3089088445&fm=253&fmt=auto?w=1243&h=800",
      price: 34.26,
      title: "4K 超窄边框智能电视"
      ),
       GoodsItem(
      picture: "https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2Flmr%2F2024%2F1008%2F10dbb3650c8ebe6b7150e0621a4387fe.jpeg&thumbnail=660x2147483647&quality=80&type=jpg",
      price: 15.66,
      title: "轻薄长续航笔记本电脑"
      ),
       GoodsItem(
      picture: "https://t11.baidu.com/it/u=393782411,210278234&fm=30&app=106&f=JPEG?w=550&h=413&s=A6804EA504C22CEA1CB9888403005043",
      price: 19.99,
      title: "真丝印花长款连衣裙"
      ),
       GoodsItem(
      picture: "https://q0.itc.cn/q_70/images03/20240312/e41acbb86a454669a49bc790faabd4fc.jpeg",
      price: 28.13,
      title: "柔软长毛绒地毯”"
      ),
       GoodsItem(
      picture: "https://img1.baidu.com/it/u=459732575,1050644040&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=375",
      price: 99.68,
      title: "全棉亲肤四件套床品"
      ),
       GoodsItem(
      picture: "https://t12.baidu.com/it/u=1412818955,259450718&fm=173&app=49&f=JPEG?w=600&h=600&s=532A6EEAA403C4FC9E073A380300D05E",
      price: 134.56,
      title: "保湿美白精华液"
      )
   ];
   ListViewCase({ super.key });
  @override
  _ListViewCase createState() => _ListViewCase();
}
// 循环渲染内容
Widget getListItem (ListViewCase widget ,int index) {
  return Container(
    padding: const EdgeInsets.all(10),
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Image.network(widget.list[index].picture,
         width: 100,
         height: 100,
         fit: BoxFit.cover,
        ),
        Container(
          height: 100,
          margin: const EdgeInsets.only(left: 20),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
             crossAxisAlignment: CrossAxisAlignment.start,
            children: [
            Text(widget.list[index].title, 
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 20
            ),),
            Text("¥${widget.list[index].price.toString()}" , 
            style: const TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.red,
                fontSize: 14
            ))
          ],
        ) ,
        )
       

      ],
    ),
  );
}

class _ListViewCase extends State<ListViewCase> {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListView.builder(itemBuilder: (BuildContext context, int index) {
        return getListItem(widget,index);
      },
      itemCount: widget.list.length,
      ),
    );
  }
}
// 1. 声明类型
class GoodsItem {
 String picture = "";
 String title = "";
 double price = 0.0;
 GoodsItem({ required this.picture, required this.price, required this.title});
}

